主题
通过DMA读取指定地址的数据Addr - DmaReadDataAddr
函数简介
通过 DMA 读取指定地址的二进制数据,使用直接地址而不是 CE 格式。(高级版功能,普通版无法使用)
接口名称
DmaReadDataAddrDLL调用
c
OLA_STRING_RETURN OLA_CALL_TYPE DmaReadDataAddr(int64_t instance, int64_t deviceId, int32_t pid, int64_t addr, int32_t len);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| deviceId | 长整数型 | 设备ID |
| pid | 整数型 | 进程 PID |
| addr | 长整数型 | 直接内存地址 |
| len | 整数型 | 读取长度(字节) |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// 先添加 DMA 设备,返回的 deviceId 用于后续读写
long deviceId = ola.DmaAddDevice(1);
string hex = ola.DmaReadDataAddr(deviceId, 1234, 0x401000, 64);csharp
using OLAPlug;
var ola = new OLAPlugServer();
// 先添加 DMA 设备,返回的 deviceId 用于后续读写
long deviceId = ola.DmaAddDevice(1);
string hex = ola.DmaReadDataAddr(deviceId, 1234, 0x401000, 64);python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
# 先添加 DMA 设备,返回的 deviceId 用于后续读写
deviceId = ola.DmaAddDevice(1)
hex = ola.DmaReadDataAddr(deviceId, 1234, 0x401000, 64)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
// 先添加 DMA 设备,返回的 deviceId 用于后续读写
long deviceId = ola.DmaAddDevice(1);
String hex = ola.DmaReadDataAddr(deviceId, 1234, 0x401000, 64);cpp
var ola = com("OlaPlug.OlaSoft")
// 先添加 DMA 设备,返回的 deviceId 用于后续读写
var deviceId = ola.DmaAddDevice(1)
var hex = ola.DmaReadDataAddr(deviceId, 1234, 0x401000, 64)vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
' 先添加 DMA 设备,返回的 deviceId 用于后续读写
deviceId = ola.DmaAddDevice(1)
hex = ola.DmaReadDataAddr(deviceId, 1234, 0x401000, 64)text
.局部变量 ola, OLAPlug
ola.创建 ()
' 先添加 DMA 设备,返回的 deviceId 用于后续读写
deviceId = ola.DmaAddDevice(1)
hex = ola.DmaReadDataAddr(deviceId, 1234, 0x401000, 64)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
// 先添加 DMA 设备,返回的 deviceId 用于后续读写
var deviceId = ola.DmaAddDevice(1);
var hex = ola.DmaReadDataAddr(deviceId, 1234, 0x401000, 64);text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
// 先添加 DMA 设备,返回的 deviceId 用于后续读写
长整数 deviceId = ola.DmaAddDevice(1)
文本型 hex = ola.DmaReadDataAddr(deviceId, 1234, 0x401000, 64)cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// 先添加 DMA 设备,返回的 deviceId 用于后续读写
long deviceId = ola.DmaAddDevice(1);
string hex = ola.DmaReadDataAddr(deviceId, 1234, 0x401000, 64);原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long deviceId = DmaAddDevice(instance, 1);
long hexPtr = DmaReadDataAddr(instance, deviceId, 1234, 0x401000, 64);
if (hexPtr != 0) {
char hex[512] = {0};
GetStringFromPtr(hexPtr, hex, sizeof(hex));
FreeStringPtr(hexPtr);
}csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
long instance = CreateCOLAPlugInterFace();
long deviceId = DmaAddDevice(instance, 1);
long hexPtr = DmaReadDataAddr(instance, deviceId, 1234, 0x401000, 64);
if (hexPtr != 0) {
StringBuilder hex = new StringBuilder(GetStringSize(hexPtr) + 1);
GetStringFromPtr(hexPtr, hex, hex.Capacity);
FreeStringPtr(hexPtr);
string hexStr = hex.ToString();
}python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
deviceId = DmaAddDevice(instance, 1)
hexPtr = DmaReadDataAddr(instance, deviceId, 1234, 0x401000, 64)
if hexPtr:
buf = create_string_buffer(512)
ola.GetStringFromPtr(hexPtr, buf, 512)
ola.FreeStringPtr(hexPtr)
hex = buf.value.decode("utf-8")返回值
字符串指针,数据格式为十六进制表示,每个字节以空格相隔,示例:12 34 56 78 ab cd ef。
返回的字符串指针需要调用 FreeStringPtr 释放内存。
